package com.corpcredit.webapp.action;

import java.io.Serializable;

import com.corpcredit.model.Jbqk;
import com.corpcredit.model.Jrjgxdxx;
import com.corpcredit.service.GenericManager;
import com.corpcredit.service.LookupManager;

public class JrjgxdxxForm extends BasePage implements Serializable {
    private GenericManager<Jrjgxdxx, Long> jrjgxdxxManager;
    private Jrjgxdxx jrjgxdxx = new Jrjgxdxx();
    private Long id;
	private LookupManager lookupManager;
	
	public void setLookupManager(LookupManager lookupManager) {
		this.lookupManager = lookupManager;
	}
    public void setJrjgxdxxManager(GenericManager<Jrjgxdxx, Long> jrjgxdxxManager) {
        this.jrjgxdxxManager = jrjgxdxxManager;
    }

    public Jrjgxdxx getJrjgxdxx() {
    	Jbqk jbqk = getJbqk();
		if (jbqk != null && jbqk.getId() != null) {
			jrjgxdxx = (Jrjgxdxx) lookupManager.findByJbqkID(Jrjgxdxx.class, jbqk.getId());
		}
		if(jrjgxdxx == null)
		{
			jrjgxdxx = new Jrjgxdxx();
		}
        return jrjgxdxx;
    }

    public void setJrjgxdxx(Jrjgxdxx jrjgxdxx) {
        this.jrjgxdxx = jrjgxdxx;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String delete() {
        jrjgxdxxManager.remove(jrjgxdxx.getId());
        addMessage("jrjgxdxx.deleted");

        return "edit";
    }

    public String save() {
        boolean isNew = (jrjgxdxx.getId() == null || jrjgxdxx.getId() == 0);
        jrjgxdxxManager.save(jrjgxdxx);

        String key = (isNew) ? "jrjgxdxx.added" : "jrjgxdxx.updated";
        addMessage(key);

        return "edit";
    }
} 